use $EMAIL environment variable as fallback
authorTshepang Lekhonkhobe <tshepang@gmail.com>
Fri, 26 Jun 2015 18:47:04 +0000 (20:47 +0200)
committerTshepang Lekhonkhobe <tshepang@gmail.com>
Fri, 26 Jun 2015 22:24:31 +0000 (00:24 +0200)
src/cargo/ops/cargo_new.rs
src/doc/config.md
tests/test_cargo_new.rs

index 3f032b4fad975bba2d1b18a3f63b22b92cb9a01e..c8b2fdca6d4c5d59b3a60118694a81db37974f6f 100644 (file)
@@ -188,7 +188,8 @@ fn discover_author() -> CargoResult<(String, Option<String>)> {
                                       user, please set ${}", username_var)))
         }
     };
-    let email = git_config.and_then(|g| g.get_string("user.email").ok());
+    let email = git_config.and_then(|g| g.get_string("user.email").ok())
+                          .or_else(|| env::var("EMAIL").ok());
 
     let name = name.trim().to_string();
     let email = email.map(|s| s.trim().to_string());
index b3f885c1fdfc0fc1e3f00b7f464a7f8365415ea2..e0678e4a2b9dfa5f36e2c2e21df36a26170231cb 100644 (file)
@@ -42,7 +42,7 @@ paths = ["/path/to/override"]
 [cargo-new]
 # This is your name/email to place in the `authors` section of a new Cargo.toml
 # that is generated. If not present, then `git` will be probed, and if that is
-# not present then `$USER` will be used (with no email).
+# not present then `$USER` and `$EMAIL` will be used.
 name = "..."
 email = "..."
 
index b885a49fcbdaf154905d71755677285edefbb5dc..1a8b5c0fa23dc970d81100b777daebc55dd2a6d5 100644 (file)
@@ -169,6 +169,22 @@ test!(finds_author_username {
     assert!(contents.contains(r#"authors = ["foo"]"#));
 });
 
+test!(finds_author_email {
+    // Use a temp dir to make sure we don't pick up .cargo/config somewhere in
+    // the hierarchy
+    let td = TempDir::new("cargo").unwrap();
+    assert_that(cargo_process("new").arg("foo")
+                                    .env("USER", "bar")
+                                    .env("EMAIL", "baz")
+                                    .cwd(td.path().clone()),
+                execs().with_status(0));
+
+    let toml = td.path().join("foo/Cargo.toml");
+    let mut contents = String::new();
+    File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
+    assert!(contents.contains(r#"authors = ["bar <baz>"]"#));
+});
+
 test!(finds_author_git {
     my_process("git").args(&["config", "--global", "user.name", "bar"])
                      .exec().unwrap();